import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CustomVO, CustomForm, CustomQuery } from '@/api/wuliu/custom/types';
import type { ListBaseQuery, ListData, ResBody } from '../common';

/**
 * 查询客户表列表
 * @param query
 * @returns {*}
 */

export const listCustom = (query?: CustomQuery): AxiosPromise<CustomVO[]> => {
  return request({
    url: '/wuliu/custom/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询客户表详细
 * @param id
 */
export const getCustom = (id: string | number): AxiosPromise<CustomVO> => {
  return request({
    url: '/wuliu/custom/' + id,
    method: 'get'
  });
};

/**
 * 新增客户表
 * @param data
 */
export const addCustom = (data: CustomForm) => {
  return request({
    url: '/wuliu/custom',
    method: 'post',
    data: data
  });
};

/**
 * 修改客户表
 * @param data
 */
export const updateCustom = (data: CustomForm) => {
  return request({
    url: '/wuliu/custom',
    method: 'put',
    data: data
  });
};

/**
 * 删除客户表
 * @param id
 */
export const delCustom = (id: string | number | Array<string | number>) => {
  return request({
    url: '/wuliu/custom/' + id,
    method: 'delete'
  });
};

export interface CustomData {
  id: number;
  deptId: number;
  customName: string;
  phone: string;
  univalence: number;
  remark: string;
}

export interface CustomListQuery extends ListBaseQuery {
  deptId?: number;
  customName?: string;
  phone?: string;
  univalence?: number;
  remark?: string;
}

export const getCustomList = (params: CustomListQuery): Promise<ListData<CustomData>> => request.get('/wuliu/custom/list', { params });

export const createCustom = (data: Partial<CustomData>): ResBody => request.post('/wuliu/custom', data);
